<?php
include "conexao.php";
$_SESSION [] = array ();
session_start ();

if (isset ( $_POST ['logar'] )) {
	$user = $_POST ['user'];
	$pwd = $_POST ['password'];
}

$sql = "Select nome,user,senha,nivel from usuario where user LIKE '$user'";

$dados = mysql_query ( $sql );

$dados = mysql_fetch_array ( $dados );
$location = '';
if ($dados [2] == $_POST ['password']) {
	header ( 'location: principal.php?pagina=home' );
	$_SESSION ["usuario"] = $dados[0];
	$_SESSION["nivel"] = $dados[3];
} else {
	header ( 'location: index.php?msg=1' );
	$_SESSION ["usuario"] = array ();
}